import java.util.Scanner;

/**
 * @description: 通过递归的方式去解决阶乘问题
 * @author: WangBlue
 * @create: 2023-10-23 21:41
 **/
public class FactorialByRec {

    /**
     * @param number 输入阶乘数
     * @return 阶乘结果
     */
    public static int Rec(int number){
        if (number < 0 ){
            return 0;
        }
        else if (number == 0 || number == 1){
            return 1;
        }
         return number * Rec(number-1);
    }


    public static void main(String[] args) {
        System.out.println("请输入你想要阶乘的数字：");
        int number = new Scanner(System.in).nextInt();
        int rec = Rec(number);

        if (rec == 0){
            System.out.println("输入的数字有误");
            return;
        }
        System.out.println("阶乘的结果为：" + rec);
    }
}
